/* 组件操作的action
 * ComponentAction.js
 */

//新增文本框组件
export function addNewLabel(pageId,text='文本框',background=''){
	return {'type':'PAGE_NEW_ADD_LABEL_COMPONENT','pageId':pageId,text:text,background:background};
}

//新增图片组件
export function addNewImage(pageId,src,imgName){
	return {'type':'PAGE_NEW_ADD_IMAGE_COMPONENT','pageId':pageId,imgSrc:src,imgName:imgName};
}

//新增单行文本输入框
export function addNewText(pageId){
	return {'type':'PAGE_NEW_ADD_TEXT_COMPONENT','pageId':pageId};
}

//新增多行文本输入框
export function addNewTextarea(pageId){
	return {'type':'PAGE_NEW_ADD_TEXTAREA_COMPONENT','pageId':pageId};
}

//新增下拉选择框
export function addNewSelect(pageId){
	return {'type':'PAGE_NEW_ADD_SELECT_COMPONENT','pageId':pageId};
}

//删除一个组件
export function deleteComp(pageId,compId){
	return {'type':'PAGE_DELETE_COMPONENT','pageId':pageId,componentId:compId};
}

/**
 * 拖动调整组件位置变化
 * sourceCompId 拖动的当前组件id
 * targetCompPos 目标位置的组件id
 */
export function changeCompOrder(pageId,sourceCompId,targetCompPos){
	return {'type':'PAGE_CHANGE_COMP_ORDER','pageId':pageId,'sourceCompId':sourceCompId,'targetCompPos':targetCompPos};
}

//修改组件名称
export function updateCompName(pageId,componentId,name){
	return {'type':'UPDATE_COMP_NAME',pageId:pageId,componentId:componentId,'compName':name};
}

//设置组件是否可见
export function handleCompHide(pageId,componentId,hide){
	return {'type':'UPDATE_COMP_HIDDEN',pageId:pageId,componentId:componentId,'compHidden':hide};
}


//修改组件的属性
export function upCompAttr(pageId,componentId,compAttr){
	return {'type':'UPDATE_COMP_ATTR',pageId:pageId,componentId:componentId,'compAttr':compAttr};
}

//修改组件的外观
export function upCompSurface(pageId,componentId,compSurface){
	return {'type':'UPDATE_COMP_SURFACE',pageId:pageId,componentId:componentId,compSurface:compSurface};
}

//修改组件的动画,默认修改第一个动画
export function upCompAnimation(pageId,componentId,compAnimation,index=0){
	return {'type':'UPDATE_COMP_ANIMATION',pageId:pageId,componentId:componentId,compAnimation:compAnimation,index:index};
}

//修改组件的事件,默认修改第一个
export function upCompEvent(pageId,componentId,compEvent,index=0){
	return {'type':'UPDATE_COMP_EVENT',pageId:pageId,componentId:componentId,compEvent:compEvent,index:index};
}

//修改组件的动画,删除一个动画
export function delCompAnimation(pageId,componentId,index){
	return {'type':'DELETE_COMP_ANIMATION',pageId:pageId,componentId:componentId,index:index};
}

//修改组件的动画,添加一个动画
export function addCompAnimation(pageId,componentId){
	return {'type':'ADD_COMP_ANIMATION',pageId:pageId,componentId:componentId};
}
